package com.example.mq.rocketmq.consumer;

import com.example.mq.rocketmq.dataobject.Mq01Message;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author luowj12
 * @since 2021/4/25 16:21
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = "DEMO_01",
        //消费模式，ORDERLY为顺序
        consumeMode = ConsumeMode.ORDERLY,
        //messageModel = MessageModel.BROADCASTING, // 设置为广播消费
        //消费者线程数
        consumeThreadMax =6,
        //selectorExpression = "tag_sync_store",
        consumerGroup = "consumer_02"
)
public class ConsumerListener2 implements RocketMQListener<Mq01Message> {
    @Override
    public void onMessage(Mq01Message message) {


        log.info("另一个消费者[onMessage][线程编号:{} 消息内容：{} 消息内容id:{}]", Thread.currentThread().getId(), message,message.getId());

        // sleep 2 秒，用于查看顺序消费的效果
        /*try {
            Thread.sleep(2 * 1000L);
        } catch (InterruptedException ignore) {
        }*/
        //测试消息重试
        //throw new RuntimeException();
    }
}
